package cn.edu.cug.cs.gtl.apis.ui.seriesuis;

import cn.edu.cug.cs.gtl.apis.ui.AbstractApplication;
import cn.edu.cug.cs.gtl.apis.ui.UIApp;

import javax.swing.*;
import java.awt.*;

public class SeriesUIApp extends UIApp {
    private JPanel mainPanel;
    public SeriesUIApp(AbstractApplication theApp) {
        super(theApp);
    }

    @Override
    public Type getType() {
        return Type.SERIES_UI_APP;
    }

    @Override
    public JComponent initializeUI() {
        if (mainPanel == null) {
            mainPanel = new JPanel();
            mainPanel.setLayout(new BorderLayout());
            mainPanel.setSize(1000, 800);
        }
        return mainPanel;
    }

    @Override
    public boolean isValid() {
        return mainPanel != null;
    }

    //更新UI为新的chartPanel
    public void updateUI(JPanel chartPanel) {
        if (isValid()) {
            mainPanel.removeAll();

            mainPanel.add(chartPanel, BorderLayout.CENTER);
            mainPanel.revalidate();
            mainPanel.repaint();
        }
    }
}
